package spotGUI.supportGUI;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import managers.SupportManager;
import managers.messengerManager.FeedbackManager;
import managers.messengerManager.MessengerManager;
import utils.StackTracePrinter;
import java.util.ResourceBundle;

public class ReportBugPanel extends JPanel{
	private JLabel title;
	private JLabel lblD1;
	private JTextField textFieldD1;
	private JLabel lblD2;
	private JTextField textFieldD2;
	private JLabel lblD3;
	private JTextArea textAreaD3;
	private JScrollPane scrollPaneD3;
	private JButton btnSend;
	private JLabel lblSent;


	
	
	public ReportBugPanel() {
		super();
		setBorder(new EmptyBorder(10, 10, 0, 10));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{424, 6, 0};
		gridBagLayout.rowHeights = new int[]{70, 0, 22, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		title = new JLabel(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("ReportBugPanel.title.text")); //$NON-NLS-1$ //$NON-NLS-2$
		GridBagConstraints gbc_title = new GridBagConstraints();
		gbc_title.fill = GridBagConstraints.HORIZONTAL;
		gbc_title.gridwidth = 2;
		gbc_title.anchor = GridBagConstraints.NORTH;
		gbc_title.insets = new Insets(0, 0, 5, 0);
		gbc_title.gridx = 0;
		gbc_title.gridy = 0;
		add(title, gbc_title);
		
		lblD1 = new JLabel(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("ReportBugPanel.lblD1.text")); //$NON-NLS-1$ //$NON-NLS-2$
		GridBagConstraints gbc_lblD1 = new GridBagConstraints();
		gbc_lblD1.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblD1.gridwidth = 2;
		gbc_lblD1.insets = new Insets(0, 0, 5, 0);
		gbc_lblD1.gridx = 0;
		gbc_lblD1.gridy = 1;
		add(lblD1, gbc_lblD1);
		
		textFieldD1 = new JTextField();
		textFieldD1.setBackground(UIManager.getColor("Desktop.background"));
		GridBagConstraints gbc_textFieldD1 = new GridBagConstraints();
		gbc_textFieldD1.gridwidth = 2;
		gbc_textFieldD1.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldD1.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldD1.gridx = 0;
		gbc_textFieldD1.gridy = 2;
		add(textFieldD1, gbc_textFieldD1);
		textFieldD1.setColumns(10);
		
		lblD2 = new JLabel(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("ReportBugPanel.lblD2.text")); //$NON-NLS-1$ //$NON-NLS-2$
		GridBagConstraints gbc_lblD2 = new GridBagConstraints();
		gbc_lblD2.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblD2.gridwidth = 2;
		gbc_lblD2.insets = new Insets(0, 0, 5, 0);
		gbc_lblD2.gridx = 0;
		gbc_lblD2.gridy = 3;
		add(lblD2, gbc_lblD2);
		
		textFieldD2 = new JTextField();
		textFieldD2.setBackground(UIManager.getColor("Desktop.background"));
		GridBagConstraints gbc_textFieldD2 = new GridBagConstraints();
		gbc_textFieldD2.gridwidth = 2;
		gbc_textFieldD2.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldD2.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldD2.gridx = 0;
		gbc_textFieldD2.gridy = 4;
		add(textFieldD2, gbc_textFieldD2);
		textFieldD2.setColumns(10);
		
		lblD3 = new JLabel(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("ReportBugPanel.lblD3.text")); //$NON-NLS-1$ //$NON-NLS-2$
		GridBagConstraints gbc_lblD3 = new GridBagConstraints();
		gbc_lblD3.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblD3.gridwidth = 2;
		gbc_lblD3.insets = new Insets(0, 0, 5, 0);
		gbc_lblD3.gridx = 0;
		gbc_lblD3.gridy = 5;
		add(lblD3, gbc_lblD3);
		
		scrollPaneD3 = new JScrollPane();
		scrollPaneD3.setOpaque(false);
		GridBagConstraints gbc_scrollPaneD3 = new GridBagConstraints();
		gbc_scrollPaneD3.gridwidth = 2;
		gbc_scrollPaneD3.insets = new Insets(0, 0, 5, 0);
		gbc_scrollPaneD3.fill = GridBagConstraints.BOTH;
		gbc_scrollPaneD3.gridx = 0;
		gbc_scrollPaneD3.gridy = 6;
		add(scrollPaneD3, gbc_scrollPaneD3);
		
		textAreaD3 = new JTextArea();
		textAreaD3.setBackground(UIManager.getColor("Desktop.background"));
		textAreaD3.setOpaque(false);
		scrollPaneD3.setViewportView(textAreaD3);
		
		btnSend = new JButton(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("ReportBugPanel.btnSend.text")); //$NON-NLS-1$ //$NON-NLS-2$
		btnSend.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblSent.setVisible (true);
				try {
					SupportManager.getSharedInstance().sendBugReport(textFieldD1.getText(), textFieldD2.getText(), textAreaD3.getText());
				} catch (Exception e1) {
					StackTracePrinter.print(e1);
					MessengerManager.getSharedInstance().getFeedbackManager().updateStatus(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("CommentPanel.error"), FeedbackManager.WARNING);
				}
			}
		});
		
		lblSent = new JLabel(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("ReportBugPanel.lblSent.text")); //$NON-NLS-1$ //$NON-NLS-2$
		lblSent.setVisible(false);
		GridBagConstraints gbc_lblSent = new GridBagConstraints();
		gbc_lblSent.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblSent.insets = new Insets(0, 0, 0, 5);
		gbc_lblSent.gridx = 0;
		gbc_lblSent.gridy = 7;
		add(lblSent, gbc_lblSent);
		GridBagConstraints gbc_btnSend = new GridBagConstraints();
		gbc_btnSend.anchor = GridBagConstraints.EAST;
		gbc_btnSend.gridx = 1;
		gbc_btnSend.gridy = 7;
		add(btnSend, gbc_btnSend);
	}

}
